<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 私有成员 私有属性和私有方法:
        // 私有成员的修饰符 #
        
        // ES5私有
        // function Person(){
        //     this.name = '张三'//公有
        //     let weight = '100kg';//由于作用域,私有
        //     console.log(weight);
        // }
        // let p = new Person()
        // console.log(p);

        // ES6
        //私有成员:只能内部调用,外部和子类不能调用
        class Person{
            #weight = '100kg';//私有
            constructor(name,weight){
                this.name = name;//公有
                this.#fn()
                this.setW(weight)
            }
            #fn(){
                console.log(this.#weight);
            }
            getW(){
                console.log('weight:',this.#weight);
            }
            setW(weight){
                this.#weight = weight
            }
        }
        let p = new Person('张三','60kg')
        console.log(p);

        console.log(p.weight);//undefined//外部调用不到
        p.weight = '120kg' //这边是静态属性,草
        // p.setW('80kg')
        p.getW()
        console.log(p.weight);//undefined//改完还是私有
    </script>
</body>
</html>